<template>
  <div>
    <div class="box">
      <div class="folder" @click="open">
        目录
        <el-checkbox
          :indeterminate="isIndeterminate"
          v-model="checkAll"
          @change="handleCheckAllChange"
        ></el-checkbox>
      </div>
      <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
        <div v-for="(item,index) in list" :key="index" class="file" v-show="show">
          <el-checkbox :title="item.fileName" :label="item.id">{{item.fileName.length>17?item.fileName.slice(0,17)+'...':item.fileName}}</el-checkbox>
          <span @click="st(item.fullPath)" class="st">试听</span>
        </div>
      </el-checkbox-group>
      <div class="audioBox" v-if="audioShow">
        <music :path="path" @close="close" />
      </div>
    </div>
  </div>
</template>
<script>
import music from "./music";
export default {
  data() {
    return {
      checkList: [],
      list: [],
      show: true,
      checkAll: false,
      checkedCities: [],
      isIndeterminate: false,
      path: "/",
      audioShow: false
    };
  },
  components: {
    music
  },
  mounted() {
    this.getList();
  },
  watch: {
    checkedCities(a) {
      this.$emit("fileId", a);
    },
    list(a) {
      console.log(a);
    }
  },
  methods: {
    st(item) {
      this.path = item;
      this.audioShow = true;
    },
    close() {
      this.audioShow = false;
    },
    handleCheckAllChange(val) {
      var arr = [];
      this.list.forEach(item => {
        arr.push(item.id);
      });

      this.checkedCities = val ? arr : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      var arr = [];
      this.list.forEach(item => {
        arr.push(item.id);
      });
      this.checkAll = checkedCount === arr.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < arr.length;
    },
    open() {
      this.show = !this.show;
    },
    getList() {
      this.$http.get("/api/threesuns/medias?page=1&size=10").then(res => {
        if (res.data.code == 200) {
          this.list = res.data.data;
          // console.log(this.list);
        }
      });
    }
  }
};
</script>
<style scoped>
.st {
  font-size: 14px;
  position: absolute;
  left: 370px;
  padding: 3px 5px;
  text-align: center;
  background-color: #00968e;
  border-radius: 30px;
  cursor: pointer;
}
.st:active {
  border: 1px solid #fff;
}
.box {
  padding-left: 15px;
  position: relative;
  overflow: hidden;
}
.folder {
  position: relative;
  overflow: hidden;
  margin-right: 5px;
  margin-left: 15px;
}
.folder::before {
  content: "";
  width: 20px;
  height: 20px;
  display: inline-block;
  background: url("../../../assets/image/SoundColumn/folder.png");
  background-size: cover;
  margin-right: 15px;
}
.file {
  padding: 5px;
  margin-left: 30px;
}

.file::before {
  content: "";
  width: 20px;
  height: 20px;
  display: inline-block;
  vertical-align: bottom;
  background: url("../../../assets/image/SoundColumn/mp3.png");
  background-size: cover;
}
.audio {
  position: absolute;
  top: 0;
  /* left: 300px;
  top: 400px; */
  z-index: 99;
  overflow: hidden;
  background-color: #fff;
}
.audioTitle {
  background-color: #00968e;
  padding: 15px;
  text-align: center;
  position: relative;
  cursor: move;
}
.el-icon-close {
  position: absolute;
  right: 10px;
  cursor: pointer;
}
.audioBox {
  width: 100%;
  height: 908px;
  position: fixed;
  z-index: 5;
}
.file /deep/ .el-checkbox__input {
  display: none;
}

.el-checkbox {
  color: #fff;
}
.folder .el-checkbox {
  margin-left: 25px;
}
/* 树 */
/deep/ .el-tree-node__expand-icon::before {
  content: "";
  width: 20px;
  height: 20px;
  display: inline-block;
  background: url("../../../assets/image/SoundColumn/folder.png");
  background-size: cover;
  margin-right: 15px;
}

/deep/ .is-leaf::before {
  content: "";
  width: 20px;
  height: 20px;
  display: inline-block;
  vertical-align: bottom;
  background: url("../../../assets/image/SoundColumn/mp3.png");
  background-size: cover;
}
/deep/ .el-tree-node__expand-icon.expanded {
  transform: none;
}
.el-tree {
  background-color: rgba(0, 0, 0, 0);
}
/deep/ .el-tree-node__content:hover {
  background-color: rgba(0, 0, 0, 0);
}
/deep/ .is-current:hover {
  background-color: rgba(0, 0, 0, 0);
}

/deep/ .el-tree-node:focus > .el-tree-node__content {
  background-color: rgba(0, 0, 0, 0);
}
</style>